import request from "@/utils/request";
import type { AxiosPromise } from "axios";
import type { DeptForm, DeptQuery, DeptVO } from "./types";

// 查询组织列表
export const listDept = (query?: DeptQuery) => {
  return request({
    url: "/system/dept/list",
    method: "get",
    params: query
  });
};

// 查询组织列表（排除节点）
export const listDeptExcludeChild = (deptId: string | number): AxiosPromise<DeptVO[]> => {
  return request({
    url: "/system/dept/list/exclude/" + deptId,
    method: "get"
  });
};

// 查询组织详细
export const getDept = (deptId: string | number): AxiosPromise<DeptVO> => {
  return request({
    url: "/system/dept/" + deptId,
    method: "get"
  });
};

// 查询组织下拉树结构
export const treeSelect = (): AxiosPromise<DeptVO[]> => {
  return request({
    url: "/system/dept/optionSelect",
    method: "get"
  });
};

// 新增组织
export const addDept = (data: DeptForm) => {
  return request({
    url: "/system/dept",
    method: "post",
    data: data
  });
};

// 修改部门
export const updateDept = (data: DeptForm) => {
  return request({
    url: "/system/dept",
    method: "put",
    data: data
  });
};

// 删除部门
export const delDept = (deptId: number | string) => {
  return request({
    url: "/system/dept/" + deptId,
    method: "delete"
  });
};
